from django.contrib.auth.models import AbstractUser, AbstractBaseUser
from django.db import models


class User(AbstractUser):
    openid = models.CharField(max_length=50, unique=True, verbose_name="openid")
    phone = models.CharField(max_length=32, verbose_name="手机号")
    sex = models.CharField(max_length=10, verbose_name="性别")


class UserWorkerInfo(models.Model):
    user = models.OneToOneField(User, db_constraint=False, on_delete=models.SET_NULL, null=True)
    education = models.CharField(max_length=32, verbose_name="学历")
    work_start_date = models.DateField(verbose_name="工作开始日期")
    work_end_date = models.DateField(verbose_name="工作结束日期")
    work_type_list = models.JSONField(verbose_name="工作领域")
    work_position_list = models.JSONField(verbose_name="工作岗位")

    other_work_type = models.CharField(blank=True, max_length=64, verbose_name="其他工作领域")
    other_work_position = models.CharField(blank=True, max_length=64, verbose_name="其他工作岗位")

    @classmethod
    def save_data(cls, data):
        obj = cls.objects.create(**data)
        return obj

    class Meta:
        verbose_name_plural = "工作信息"
